<?php
ob_start();
session_start();
if(class_exists('SQL_Helper') != true)
{
   include_once("php/sql_helper.php");
};
// include_once("php/sql_helper.php");
function isValidLogin ($username, $password){
	$row=SQL_Helper::executeQuerySingle("Select `password` from `teams` where `teamID` = ?", $username);
	return $password==$row[0];
}
function loginName ($teamID){
	$row=SQL_Helper::executeQuerySingle("Select `team_name` from `teams` where `teamID` = ?", $teamID);
	return $row[0];
}
$username=$_POST['username'];
$password=$_POST['password'];

if (isValidLogin($username,$password)){
	$_SESSION['teamID']=$username;
	$_SESSION['login'] = loginName($username); 
	header('LOCATION:'.$_SERVER["HTTP_REFERER"]);
}
else {
	//header('LOCATION:login_failed.php');
	$_SESSION['login_failed'] = true; 
	header('LOCATION:'.$_SERVER["HTTP_REFERER"]);
}

ob_flush();
?>
